package com.itmg.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.itmg.dao.CategoryDAO;
import com.itmg.dao.model.CategoryModel;

public class CategoryDAOImpl extends SqlMapClientDaoSupport implements CategoryDAO {

	//得到所有的类型信息
	public List<CategoryModel> getCategory() throws Exception{
		List<CategoryModel> list = new ArrayList<CategoryModel>();
		Connection con = null;
		String sql = "select * from shop_category";
		try {
			con = getSqlMapClientTemplate().getDataSource().getConnection();
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery(sql);
			while(rs.next()){
				CategoryModel model = new CategoryModel();
				model.setId(rs.getInt("id"));
				model.setCategory_id(rs.getInt("category_id"));
				model.setCategory_name(rs.getString("category_name"));
				model.setKakaku_name(rs.getString("kakaku_name"));
				model.setAmazon_name(rs.getString("amazon_name"));
				list.add(model);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
}
